package com.github.cakin.shiro.chapter20.mgt;

import org.apache.shiro.subject.Subject;
import org.apache.shiro.subject.SubjectContext;
import org.apache.shiro.web.mgt.DefaultWebSubjectFactory;

/**
 * @className: StatelessDefaultSubjectFactory
 * @description: 创建无状态的Subject
 * @date: 2020/5/29
 * @author: cakin
 */
public class StatelessDefaultSubjectFactory extends DefaultWebSubjectFactory {

    @Override
    public Subject createSubject(SubjectContext context) {
        // context.setSessionCreationEnabled(false) 表示不创建会话；
        // 如果之后调用 Subject.getSession() 将抛出 DisabledSessionException 异常。
        context.setSessionCreationEnabled(false);
        return super.createSubject(context);
    }
}
